Outer Product between Two Vectors
This is an example of how to use the csdl outer function to compute the outer product between two vectors.
from csdl_om import Simulatorfrom csdl import Modelimport csdlimport numpy as np
class ExampleVectorVector(Model):
def define(self):
m = 3
# Shape of the vectors vec_shape = (m, )
# Values for the two vectors vec1 = np.arange(m) vec2 = np.arange(m, 2 * m)
# Adding the vectors to csdl vec1 = self.declare_variable('vec1', val=vec1) vec2 = self.declare_variable('vec2', val=vec2)
# Vector-Vector Outer Product self.register_output('VecVecOuter', csdl.outer(vec1, vec2))
sim = Simulator(ExampleVectorVector())sim.run()
print('vec1', sim['vec1'].shape)print(sim['vec1'])print('vec2', sim['vec2'].shape)print(sim['vec2'])print('VecVecOuter', sim['VecVecOuter'].shape)print(sim['VecVecOuter'])
[0. 1. 2.]vec2 (3,)[3. 4. 5.]VecVecOuter (3, 3)[[ 0. 0. 0.] [ 3. 4. 5.] [ 6. 8. 10.]]